<?php

declare (strict_types = 1);

namespace app\common\service\user;

use app\common\service\BaseService;
use app\common\repository\user\UserWithdrawRepository;

class UserWithdrawService extends BaseService
{
    public function __construct(UserWithdrawRepository $repository)
    {
        $this->repository = $repository;
    }

    /**
     * 获取列表
     *
     * @return \think\model\Collection|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getList(): \think\model\Collection|\think\Collection
    {
        return $this->repository->getByWhere([], ['create_time' => 'desc']);
    }

    /**
     * 新增
     *
     * @param array $data
     * @return \think\Collection|\app\common\model\BaseModel|array
     * @throws \Exception
     */
    public function create(array $data): \think\Collection|\app\common\model\BaseModel|array
    {
        return $this->repository->save($data);
    }

    /**
     * 修改
     *
     * @param array $data
     * @param $where
     * @return \app\common\model\BaseModel|bool|int
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function update(array $data, $where): \app\common\model\BaseModel|bool|int
    {
        return $this->repository->update($data, $where);
    }

    /**
     * 获取详情
     *
     * @param $where
     * @return \app\common\model\BaseModel|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getInfo($where): ?\app\common\model\BaseModel
    {
        return $this->repository->getOne($where);
    }

    /**
     * 删除
     *
     * @param $where
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function delete($where): bool
    {
        return $this->repository->delete($where);
    }

    /**
     * 用户提现USDT记录
     *
     * @param $user_id
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     */
    public function getRecordList($user_id): array
    {
        [$page, $pageSize] = $this->getPaginationParams();
        $where = ['user_id' => $user_id];
        return $this->repository->paginate($where, ['create_time' => 'desc'], $page, $pageSize);
    }
}